# -*- coding: utf-8 -*-
from __future__ import unicode_literals
 
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
 

class nodegroup(models.Model):
    nodegroup_name = models.CharField('节点组', max_length=100,unique=True)
    area = models.CharField('地域', max_length=100, blank=True)

    def __unicode__(self):
        return self.nodegroup_name

    class Meta:
        verbose_name = '节点组'
        verbose_name_plural = '节点组'
        ordering = ['area']  # 按照哪个栏目排序


class route(models.Model):
    route_name = models.CharField('线路', max_length=100, unique=True)
    area = models.CharField('地域', max_length=100, blank=True)

    def __unicode__(self):
        return self.route_name

    class Meta:
        verbose_name = '线路'
        verbose_name_plural = '线路'
        ordering = ['area']  # 按照哪个栏目排序


class node_info(models.Model):
    node_access = models.CharField('授权状态', max_length=2, blank=True)
    node_name = models.CharField('节点名称', max_length=255)
    NodeIP = models.CharField('节点ip', max_length=20, unique=True)
    Status = models.CharField('状态', max_length=20, blank=True)
    IP0 = models.CharField('ip', max_length=20, blank=True)
    Netmask0 = models.CharField('netmask', max_length=20, blank=True)
    IP1 =  models.CharField('ip1', max_length=20, blank=True)
    Netmask1 = models.CharField('netmask1', max_length=20, blank=True)
    System_release = models.CharField('System_release', max_length=100, blank=True)
    Kernel_release = models.CharField('Kernel_release', max_length=100, blank=True)
    Frequency = models.CharField('Frequency', max_length=100, blank=True)
    CPU_cores = models.CharField('CPU_cores', max_length=100, blank=True)
    Mem_total = models.CharField('Mem_total', max_length=10, blank=True)
    Swap_total = models.CharField('Swap_total', max_length=10, blank=True)
    Disk_total = models.CharField('Disk_total', max_length=10, blank=True)
    cpu = models.CharField('cpu', max_length=20, blank=True)
    cpu_free = models.CharField('cpu_free', max_length=20, blank=True)
    eth0 = models.CharField('eth0', max_length=20, blank=True)
    send_rate0 = models.CharField('send_rate0', max_length=20, blank=True)
    recv_rate0 = models.CharField('recv_rate0', max_length=20, blank=True)
    send_all_rate0 = models.CharField('send_all_rate0', max_length=20, blank=True)
    recv_all_rate0 = models.CharField('recv_all_rate0', max_length=20, blank=True)
    eth1 = models.CharField('eth1', max_length=20, blank=True)
    send_rate1 = models.CharField('send_rate1', max_length=20, blank=True)
    recv_rate1 = models.CharField('recv_rate1', max_length=20, blank=True)
    send_all_rate1 = models.CharField('send_all_rate1', max_length=20, blank=True)
    recv_all_rate1 = models.CharField('recv_all_rate1', max_length=20, blank=True)
    Mem_used = models.CharField('Mem_used', max_length=10, blank=True)
    Mem_free = models.CharField('Mem_free', max_length=10, blank=True)
    Mem_per = models.CharField('Mem_per', max_length=10, blank=True)
    Swap_used = models.CharField('Swap_used', max_length=10, blank=True)
    Swap_free = models.CharField('Swap_free', max_length=10, blank=True)
    Swap_per = models.CharField('Swap_per', max_length=10, blank=True)
    Disk_used = models.CharField('Disk_used', max_length=10, blank=True)
    Disk_free = models.CharField('Disk_free', max_length=10, blank=True)
    Disk_per = models.CharField('Disk_per', max_length=10, blank=True)
    cache = models.CharField('cache', max_length=10, blank=True)
    token = models.CharField('节点密钥', max_length=100, blank=True)
    nodegroup = models.ForeignKey(nodegroup,default='默认组')
    route = models.ForeignKey(route,default='电信')

    def __unicode__(self):
        return self.node_name

    def toJSON(self):
        import json
        return json.dumps(dict([(attr, getattr(self, attr)) for attr in [f.name for f in self._meta.fields]]))


    class Meta:
        verbose_name = '节点名称'
        verbose_name_plural = '节点名称'
        ordering = ['node_name']  # 按照哪个栏目排序

